/*
 * @Author: 黄达全
 * @Date: 2024-07-20 22:51:20
 * @LastEditTime: 2024-08-21 13:37:27
 */
/*
 * @Author: 黄达全
 * @Date: 2024-07-20 22:51:20
 * @LastEditTime: 2024-07-20 23:59:15
 */
import { ElNotification, ElMessage, ElMessageBox } from 'element-plus'
import type { UseElementPlus, Notification, Message, MessageBox } from "@/common/type"

const useElementPlus = (): UseElementPlus => {

  /**
   *element-plus的通知组件
   *
   * @param {*} config
   */
  const notification: Notification = (config) => {
    ElNotification({
      title: config.title,
      message: config.message,
      type: config.type,
      duration: config.duration == null ? 3000 : config.duration
    })
  }

  /**element-plus的消息提示组件
   * 
   * @param config 
   */
  const message: Message = (config) => {
    ElMessage({
      message: config.message,
      type: config.type,
      duration: config.duration == null ? 3000 : config.duration
    })
  }

  const messageBox: MessageBox = (title, message, type) => {
    return ElMessageBox.confirm(
      message,
      title,
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type,
      }
    )
  }

  return {
    notification,
    message,
    messageBox
  }
}

export default useElementPlus
